Source code for hysop.constants

#
# Copyright (c) HySoP 2011-2024
#
# This file is part of HySoP software.
# See "https://particle_methods.gricad-pages.univ-grenoble-alpes.fr/hysop-doc/"
# for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

"""Default values for constant parameters used
in hysop package.

Mostly deals with float/int numbers precision and
some labels for numerical methods and operators.

This file is generated from constants.py.in
and it's probably a bad idea to modify it.
"""

import math, inspect, os
import itertools as it
import numpy as np

import hysop
from hysop import __VERBOSE__, __DEBUG__, __PROFILE__,\
                  __KERNEL_DEBUG__, __MPI_ENABLED__
from hysop.tools.henum  import EnumFactory

if __MPI_ENABLED__:
    from hysop.core.mpi import MPI

HYSOP_ROOT=os.path.dirname(inspect.getfile(hysop))

PI = math.pi

HYSOP_REAL = np.float64
"""Set default type for real numbers"""
SIZEOF_HYSOP_REAL = int(HYSOP_REAL(1.).nbytes)
"""Size in memory of hysop real default type"""

assert HYSOP_REAL in [np.float32, np.float64]
HYSOP_COMPLEX = (np.complex128 if (HYSOP_REAL==np.float64) else np.complex64)
"""Set default type for complex numbers"""
SIZEOF_HYSOP_COMPLEX = int(HYSOP_COMPLEX(1.).nbytes)
"""Size in memory of hysop complex default type"""

HYSOP_INDEX = np.uint32
"""type for array indices"""
SIZEOF_HYSOP_INDEX = int(HYSOP_INDEX(1).nbytes)
"""Size in memory of hysop index type"""

HYSOP_INTEGER = np.int32
"""type for integers"""
SIZEOF_HYSOP_INTEGER = int(HYSOP_INTEGER(1).nbytes)
"""Size in memory of hysop integer type"""

HYSOP_DIM = np.int32
"""integer used for arrays dimensions"""
SIZEOF_HYSOP_DIM = int(HYSOP_DIM(1).nbytes)
"""Size in memory of hysop dim type"""

HYSOP_BOOL = np.uint8
"""type for booleans"""
SIZEOF_HYSOP_BOOL = int(HYSOP_BOOL(1).nbytes)
"""Size in memory of hysop boolean type"""

HYSOP_EPS = np.finfo(HYSOP_REAL).eps
"""machine epsilon for HYSOP_REAL"""

HYSOP_ORDER = 'C'
"""default array layout (fortran or C convention)"""

if __MPI_ENABLED__:
    HYSOP_MPI_REAL = MPI.DOUBLE
    """float type used in MPI"""

    HYSOP_MPI_INTEGER = MPI.INT
    """integer type used in MPI"""

    HYSOP_DEFAULT_TASK_ID = 999
    """Default value for task id (mpi task)"""

System = EnumFactory.create('System',
['WINDOWS', 'DARWIN', 'LINUX'])
"""
System type enum.
"""

Backend = EnumFactory.create('Backend',
        ['OPENCL','HOST','CUDA'])
"""Operator backends"""

Implementation = EnumFactory.create('Implementation',
        ['OPENCL', 'PYTHON', 'FORTRAN', 'CPP'])
"""Operator implementations"""

[docs] def implementation_to_backend(implementation): if implementation in (Implementation.PYTHON, Implementation.FORTRAN, Implementation.CPP,): return Backend.HOST elif implementation in (Implementation.OPENCL,): return Backend.OPENCL else: msg='Unknown implementation key {}.'.format(implementation) raise ValueError(msg)
GhostOperation = EnumFactory.create('GhostOperation', ['EXCHANGE', 'ACCUMULATE']) GhostMask = EnumFactory.create('GhostMask', ['CROSS', 'FULL']) ExchangeMethod = EnumFactory.create('ExchangeMethod', ['ISEND_IRECV', 'NEIGHBOR_ALL_TO_ALL_V', 'NEIGHBOR_ALL_TO_ALL_W']) SpectralTransformAction = EnumFactory.create('SpectralTransformAction', ['OVERWRITE', 'ACCUMULATE']) Precision = EnumFactory.create('Precision', ['DEFAULT', 'SAME', 'QUAD', 'LONG_DOUBLE', 'DOUBLE', 'FLOAT', 'HALF']) """Real number precision configuration (default_precision = HYSOP_REAL).""" MemoryOrdering = EnumFactory.create('MemoryOrdering', ['C_CONTIGUOUS','F_CONTIGUOUS','OUT_OF_ORDER', 'SAME_ORDER', 'ANY']) """Memory ordering enum""" MemoryType = EnumFactory.create('MemoryType', ['GLOBAL_MEMORY', 'LOCAL_MEMORY','PRIVATE_MEMORY','CONSTANT_MEMORY']) """Memory type enum""" DeviceType = EnumFactory.create('DeviceType', ['ALL','ACCELERATOR','CPU','CUSTOM','GPU','DEFAULT']) """Device type enum""" CacheType = EnumFactory.create('CacheType', ['NONE','READ_ONLY_CACHE','READ_WRITE_CACHE']) """Cache type enum""" FpConfig = EnumFactory.create('FpConfig', ['CORRECTLY_ROUNDED_DIVIDE_SQRT', 'DENORM', 'FMA', 'INF_NAN', 'ROUND_TO_INF', 'ROUND_TO_NEAREST', 'ROUND_TO_ZERO', 'SOFT_FLOAT']) """Floating point flags""" DirectionLabels = 'XYZAB' """Directions labels up to 5d""" Directions = EnumFactory.create('Directions', DirectionLabels.split()) """Directions enum""" BoxBoundaryCondition = EnumFactory.create('BoxBoundaryCondition', [ 'PERIODIC', 'SYMMETRIC', # no slip (wall-like): Un=0 and dU||/dn = 0 'OUTFLOW' ]) # dUn/dn = 0 and U|| = 0 """Box boundary conditions enum.""" BoundaryCondition = EnumFactory.create('BoundaryCondition', [ 'NONE', # => boundaries are already in ghosts 'PERIODIC', 'MIXED', 'HOMOGENEOUS_NEUMANN', 'HOMOGENEOUS_DIRICHLET', 'NEUMANN', 'DIRICHLET' ]) """Boundary conditions enum"""
[docs] class BoundaryConditionConfig(object): def __init__(self, bc, data=None): assert isinstance(bc, BoundaryCondition), type(bc) self.bc = bc self.data = data def __str__(self): return bc.__str__()[:-1] + ', {})'.format(self.data) def __repr__(self): return bc.__repr__()[:-1] + ', {})'.format(self.data)
for bc in BoundaryCondition.fields(): bc = getattr(BoundaryCondition, bc) bc.bc = bc bc.bind_data = lambda data, bc=bc: BoundaryConditionConfig(bc=bc, data=data)
[docs] def boundary2str(b): """Helper function to convert a BoundaryCondition to a short string.""" if isinstance(b, BoundaryConditionConfig): b = b.bc sstr = { BoundaryCondition.NONE: 'NONE', BoundaryCondition.MIXED: 'MIXED', BoundaryCondition.PERIODIC: 'PER', BoundaryCondition.HOMOGENEOUS_NEUMANN: 'HNEU', BoundaryCondition.HOMOGENEOUS_DIRICHLET: 'HDIR', BoundaryCondition.NEUMANN: 'NEU', BoundaryCondition.DIRICHLET: 'DIR', } if b in sstr: return sstr[b] else: return str(b)
[docs] def format_boundaries(lboundaries, rboundaries): """Helper function format boundary conditions.""" return ','.join(('{}/{}'.format(boundary2str(lb), boundary2str(rb)) for (lb,rb) in zip(lboundaries, rboundaries)))
BoundaryExtension = EnumFactory.create('BoundaryExtension', ['PERIODIC', 'EVEN', 'ODD']) TransformType = EnumFactory.create('Transform', ['NONE', 'FFT', 'IFFT', 'RFFT', 'IRFFT', 'DCT_I', 'DCT_II', 'DCT_III', 'DCT_IV', 'DST_I', 'DST_II', 'DST_III', 'DST_IV', 'IDCT_I', 'IDCT_II', 'IDCT_III', 'IDCT_IV', 'IDST_I', 'IDST_II', 'IDST_III', 'IDST_IV']) FieldProjection = EnumFactory.create('FieldProjection', ['NONE', 'EVERY_STEP']) """Field projection mode for Poisson solver""" StretchingFormulation = EnumFactory.create('StretchingFormulation', ['GRAD_UW', 'GRAD_UW_T', 'MIXED_GRAD_UW', 'CONSERVATIVE']) """Stretching formulations""" PenalizationFormulation = EnumFactory.create( 'PenalizationFormulation', ['IMPLICIT', 'EXACT']) """Penalization formulations""" SpaceDiscretization = EnumFactory.create('SpaceDiscretization', ['FDC2', 'FDC4', 'FDC6', 'FDC8']) """Space discretization for stencil generation""" SymbolicExpressionKind = EnumFactory.create('SymbolicExpressionKind', ['AFFECT', 'TIME_INTEGRATE']) """Expression kinds for custom symbolic operators.""" AdvectionCriteria = EnumFactory.create('AdvectionCriteria', ['W_INF', 'GRAD_U', 'DEFORMATION']) StretchingCriteria = EnumFactory.create('StretchingCritetia', ['GRAD_U']) AutotunerFlags = EnumFactory.create('AutotunerFlags', ['ESTIMATE', 'MEASURE', 'PATIENT', 'EXHAUSTIVE']) """Configuration flags for kernel autotuner (automatic runtime parameters tuning for cuda and opencl).""" DEFAULT_AUTOTUNER_FLAG = AutotunerFlags.MEASURE DEFAULT_AUTOTUNER_PRUNE_THRESHOLD = 1.20 TimeIntegratorsOptimisationLevel = EnumFactory.create('TimeIntegratorsOptimisationLevel', \ ['WITH_GUESS', 'NOALIAS']) """ Optimisation level for time integrators. WITH_GUESS: no need to recompute the right-hand side, an initial guess must be given in input arguments. NOALIAS: no need to recompute the right-hand side, an initial guess must be given in input arguments and we ensure that y is different from result arg. """ ResidualError = EnumFactory.create('ResidualError', ['ABSOLUTE', 'RELATIVE']) """Space discretization for stencil generation""" default_order = None """ Default HySoP memory ordering for array allocations. """ if HYSOP_ORDER == 'F': default_order = MemoryOrdering.F_CONTIGUOUS raise RuntimeError('Fortran ordering is unsupported yet, codebase needs to be reviewed.') elif HYSOP_ORDER == 'C': default_order = MemoryOrdering.C_CONTIGUOUS else: msg='HYSOP_ORDER should be \'F\' or \'C\' (got {}).' raise ValueError(msg.format(HYSOP_ORDER)) from hysop.tools.transposition_states import TranspositionState, \ TranspositionState1D, TranspositionState2D, TranspositionState3D, \ DirectionLabels
[docs] class ComputeGranularity(object): pass